const messageEl = document ? document.querySelector(".message") : null;

export class Message {
  // construct(tip) {
  //   this.messageText = data
  //   messageEl.innerHTML = tip
  // }
  createMessageEl() {
    const div = document.createElement("div");
    div.className = "message";
    document.querySelector("body").appendChild(div);
    return div;
  }

  getMessageEl() {
    const messageEl = document.querySelector(".message");
    if (!messageEl) return this.createMessageEl();
    else return messageEl;
  }

  error(tip) {
    const messageEl = this.getMessageEl();
    // messageEl.className = 'message'
    messageEl.children[1].innerHTML = tip;
    messageEl.style.display = "block";
    setTimeout(() => {
      messageEl.style.display = "none";
    }, 1500);
  }
}

export function message() {
  return new Message();
}
